<?php 

class Users {

	public function __construct(){
		$this->query = DB::table('user');
	}

	public function addUsers($user_array) {
		$user_array['ctime'] = date('Y-m-j g:i:s');
		$user_array['mtime'] = time();
		$user = DB::table('user')->where('username', '=', $user_array['username'])->get();
		if(!empty($user)) return UMSErrcode::USER_EXIST;
		return $this->query->insert($user_array);
	}

	public function updateUsers($id,$user_array){
		$user_array['mtime'] = time();
		return $this->query
			->where('id', '=', $id)
			->update($user_array);		
	}

	public function deleteUsers($id){
		return $this->query
			->where('id', '=', $id)->delete();
	}

	public function getUserId($username){
		return $this->query
			->where('username', '=', $username)->get();
	}
	public function getUsers($id){
		return $this->query
			->find($id);
	}

	public function listUsers($per_page){
		$ret = $this->query->order_by('ctime', 'desc')
			->paginate($per_page, array('id', 'username', 'is_checked', 'phone','gender','email','ctime'));
		return $ret;
	}
}







?>

